package edu.seu.mart.dao.impl;

import edu.seu.mart.dao.BaseDao;
import edu.seu.mart.dao.ICommentDao;
import edu.seu.mart.entity.Pager;
import edu.seu.mart.model.Comment;
import org.springframework.stereotype.Repository;

/**
 * Created by Administrator on 2015/3/24.
 */
@Repository("commentDao")
public class CommentDao extends BaseDao<Comment> implements ICommentDao {

    @Override
    public Pager<Comment> findCommentByGoods(int goodsId) {
        return this.find("from Comment where goodsId = '" + goodsId + "'");
    }

    @Override
    public Pager<Comment> findCommentByLevel(int goodsId, String level) {
        Pager<Comment> comments= new Pager<Comment>();
        if (level.equals("good")) {
            comments= this.find("from Comment where goodsId = '" + goodsId + "' and review='" + 4 + " ' or review='" + 5 + " '");
        }
        else if(level.equals("middle")){

            comments= this.find("from Comment where goodsId = '" + goodsId + "' and review='" + 3 + " '");
        }
        else if(level.equals("bad")){

            comments= this.find("from Comment where goodsId = '" + goodsId + "' and review='" + 1 + " ' or review='" + 2 + " '");

        }
        return comments;
    }

}